package org.spring.cloud.service.impl;


import org.spring.cloud.constant.Constants;
import org.spring.cloud.service.GenerateOrderService;
import org.spring.cloud.util.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class GenerateOrderServiceImpl implements GenerateOrderService{

	@Autowired
	private RedisTemplate<String, Object> redisTemplate;
	
	@Override
	public String generateOrder(String prefix, Integer length) {
		Long currentOrderNo = this.redisTemplate.opsForValue().increment(Constants.ORDER_NO,1L);
		return  prefix+ String.format("%s%0"+length+"d", DateUtils.getCurrDate(), currentOrderNo);
	}

}
